package f.h.dragon.util;

import f.h.dragon.util.Arrays;

/**
 * Array: 自定义数组包装类，优化数组某些操作 The <code>Array</code> class wraps a value of the
 * primitive type <code>int[]</code> in an object. An object of type
 * <code>Array</code> contains a single field whose type is <code>int[]</code>.
 * 
 * @author Wenlong Meng(wenlong.meng@gmail.com)
 * @version 1.0 at 2012/02/07
 * @since 1.0
 */
public class Array {

	// local variables
	/**
	 * store ints
	 */
	private int[] ints;

	// Constructor
	/**
	 * Constructs a newly allocated <code>Array</code> object that represents
	 * the specified <code>int[]</code> value.
	 * 
	 * @param ints
	 *            the value to be represented by the <code>Integer</code>
	 *            object.
	 */
	public Array(int[] ints) {
		this.ints = ints;
	}

	// Logic
	/**
	 * Swaps x[a] with x[b]
	 * 
	 * @param a
	 * @param b
	 */
	public void swap(int a, int b) {
		Arrays.swap(this.ints, a, b);
	}

	/**
	 * Swaps x[a .. (a+n-1)] with x[b .. (b+n-1)].
	 * 
	 * @param x
	 * @param a
	 * @param b
	 * @param n
	 */
	public void swap(int a, int b, int n) {
		Arrays.swap(this.ints, a, b, n);
	}

	/**
	 * Returns the element at the specified position in this list.
	 * 
	 * @param index
	 *            index of the element to return
	 * @return the element at the specified position in this list
	 * @throws ArrayIndexOutOfBoundsException - if index is not in range
	 */
	public int get(int index) {
		return ints[index];
	}

	// setter and getter
	/**
	 * @return the ints
	 */
	public int[] getInts() {
		return ints;
	}

	/**
	 * @param ints
	 *            the ints to set
	 */
	public void setInts(int[] ints) {
		this.ints = ints;
	}

	// test
	/**
	 * test...
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		int[][] ints = new int[32][];
		ints[0] = new int[]{1};
		System.out.println(ints[0][0]);
		System.out.println(ints[1]);
		System.out.println(ints[1][0]);
	}

}
